﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using Common;

namespace BearingOiling
{
    /// <summary>
    /// App.xaml 的交互逻辑
    /// </summary>
    public partial class App : Application
    {
        public App()
        {
            Process pCurrent = Process.GetCurrentProcess();
            Process[] pList = Process.GetProcessesByName(pCurrent.ProcessName);
            if (pList.Length >= 2)
            {
                MessageBox.Show("只能运行一个！");
                Environment.Exit(0);
                return;
            }
            this.DispatcherUnhandledException += App_DispatcherUnhandledException;
            try
            {
                MainWindow win = new MainWindow();
                Current.MainWindow = win;
                win.Show();
            }
            catch (Exception ex)
            {
                Logger.WriteSysLog("运行失败！", ex);
            }
        }

        private void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
        {
            e.Handled = true;
            Logger.WriteSysLog("运行失败！", e.Exception);
            MessageBox.Show(e.Exception.Message + e.Exception.StackTrace);
        }

    }
}
